package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RequestMapping("/strategy")
@RestController
public class DbController {

    @Autowired
    private AlarmStrategyDao alarmStrategyDao;

    @PostMapping(value = "/list")
    public List<AlarmStrategy> listAlarmStrategy() {
        return alarmStrategyDao.selectList(null);
    }

    @PostMapping(value = "/add")
    public String addAlarmStrategy(@RequestBody AlarmStrategy alarmStrategy) {
        alarmStrategyDao.insert(alarmStrategy);
        return "ok";
    }

    @GetMapping(value = "/getById")
    public ResultData selAlarmStrategy(String id) {
        AlarmStrategy alarmStrategy = alarmStrategyDao.selectById(id);
        return ResultData.success(alarmStrategy);
    }


    @GetMapping(value = "/get")
    public String selAlarmStrategy() {
        AlarmStrategy alarmStrategy = new AlarmStrategy();
        alarmStrategy.setStrategyName("测试策略1");
        alarmStrategy.setCreateTime(new Date());
        alarmStrategy.setUpdateTime(new Date());
        alarmStrategyDao.insert(alarmStrategy);
        return "ok";
    }

}
